{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "C:\\ProgramData\\Anaconda3\\lib\\site-packages\\h5py\\__init__.py:34: FutureWarning: Conversion of the second argument of issubdtype from `float` to `np.floating` is deprecated. In future, it will be treated as `np.float64 == np.dtype(float).type`.\n",
      "  from ._conv import register_converters as _register_converters\n"
     ]
    }
   ],
   "source": [
    "import tensorflow as tf\n",
    "import os\n",
    "import tarfile\n",
    "import requests"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "# 下载网址\n",
    "inception_model_url = \"http://download.tensorflow.org/models/image/imagenet/inception-2015-12-05.tgz\"\n",
    "# requests.get(inception_model_url)\n",
    "# 存放DIR\n",
    "inception_model_dir = \"c:/learn/inception_model\"\n",
    "\n",
    "filepath = os.path.join(inception_model_dir, \"inception-2015-12-05.tgz\")\n",
    "\n",
    "with open(filepath, \"wb\") as f:\n",
    "    r = requests.get(inception_model_url, stream=True)\n",
    "    f.write(r.content)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "inception_model_dir = \"c:/learn/inception_model\"\n",
    "filepath = os.path.join(inception_model_dir, \"inception-2015-12-05.tgz\")\n",
    "\n",
    "tarfile.open(filepath, \"r:gz\").extractall(inception_model_dir)\n",
    "\n",
    "\n",
    "log_dir = \"c:/learn/inception_log\"\n",
    "\n",
    "inception_graph_def_file = os.path.join(inception_model_dir, \"classifly_image_graph_def.pb\")\n",
    "\n",
    "with tf.Session() as sess:\n",
    "\n",
    "    with tf.gfile.FastGFile(inception_graph_def_file, \"rb\") as f:\n",
    "        graph_def = tf.GraphDef()\n",
    "        graph_def.ParseFromString(f.read())\n",
    "        tf.import_graph_def(graph_def, name=\"\")\n",
    "    writer = tf.summary.FileWriter(log_dir, sess.graph)\n",
    "    writer.close()\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
